home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / glibmm-2.4 / glibmm / optioncontext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-04-20  |  6.7 KB  |  200 lines

  1. // -*- c++ -*-
  2. // Generated by gtkmmproc -- DO NOT MODIFY!
  3. #ifndef _GLIBMM_OPTIONCONTEXT_H
  4. #define _GLIBMM_OPTIONCONTEXT_H
  5.  
  6.  
  7. /* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */
  8.  
  9. /* Copyright (C) 2004 The glibmm Development Team
  10.  *
  11.  * This library is free software; you can redistribute it and/or
  12.  * modify it under the terms of the GNU Library General Public
  13.  * License as published by the Free Software Foundation; either
  14.  * version 2 of the License, or (at your option) any later version.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Library General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Library General Public
  22.  * License along with this library; if not, write to the Free
  23.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26.  
  27. #include <glibmm/optionentry.h>
  28. #include <glibmm/optiongroup.h>
  29. #include <glibmm/error.h>
  30.  
  31. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  32. extern "C" { typedef struct _GOptionContext GOptionContext; }
  33. #endif
  34.  
  35.  
  36. namespace Glib
  37. {
  38.  
  39. /** Exception class for options.
  40.  */
  41. class OptionError : public Glib::Error
  42. {
  43. public:
  44.   enum Code
  45.   {
  46.     UNKNOWN_OPTION,
  47.     BAD_VALUE,
  48.     FAILED
  49.   };
  50.  
  51.   OptionError(Code error_code, const Glib::ustring& error_message);
  52.   explicit OptionError(GError* gobject);
  53.   Code code() const;
  54.  
  55. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  56. private:
  57.   static void throw_func(GError* gobject);
  58.   friend void wrap_init(); // uses throw_func()
  59. #endif
  60. };
  61.  
  62.  
  63. /** An OptionContext defines which options are accepted by the commandline option parser.
  64.  */
  65. class OptionContext
  66. {
  67.   public:
  68. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  69.   typedef OptionContext CppObjectType;
  70.   typedef GOptionContext BaseObjectType;
  71. #endif /* DOXYGEN_SHOULD_SKIP_THIS */
  72.  
  73. private:
  74.  
  75. public:
  76.  
  77.   /** Creates a new option context.
  78.    * @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...]
  79.    */
  80.   explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
  81.   
  82.   //Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance,
  83.   //so it should be used carefully. For instance you could not access data in a derived class via this second instance.
  84.   explicit OptionContext(GOptionContext* castitem, bool take_ownership = false);
  85.   virtual ~OptionContext();
  86.   
  87.   
  88.   /** Enables or disables automatic generation of <option>--help</option> 
  89.    * output. By default, g_option_context_parse() recognizes
  90.    * <option>--help</option>, <option>-?</option>, <option>--help-all</option>
  91.    * and <option>--help-</option><replaceable>groupname</replaceable> and creates
  92.    * suitable output to stdout. 
  93.    * 
  94.    * Since: 2.6
  95.    * @param help_enabled <tt>true</tt> to enable <option>--help</option>, <tt>false</tt> to disable it.
  96.    */
  97.   void set_help_enabled(bool help_enabled = true);
  98.   
  99.   /** Returns whether automatic <option>--help</option> generation
  100.    * is turned on for @a context . See g_option_context_set_help_enabled().
  101.    * @return <tt>true</tt> if automatic help generation is turned on.
  102.    * 
  103.    * Since: 2.6.
  104.    */
  105.   bool get_help_enabled() const;
  106.   
  107.   /** Sets whether to ignore unknown options or not. If an argument is 
  108.    * ignored, it is left in the @a argv  array after parsing. By default, 
  109.    * g_option_context_parse() treats unknown options as error.
  110.    * 
  111.    * This setting does not affect non-option arguments (i.e. arguments 
  112.    * which don't start with a dash). But note that GOption cannot reliably
  113.    * determine whether a non-option belongs to a preceding unknown option.
  114.    * 
  115.    * Since: 2.6
  116.    * @param ignore_unknown <tt>true</tt> to ignore unknown options, <tt>false</tt> to produce
  117.    * an error when unknown options are met.
  118.    */
  119.   void set_ignore_unknown_options(bool ignore_unknown = true);
  120.   
  121.   /** Returns whether unknown options are ignored or not. See
  122.    * g_option_context_set_ignore_unknown_options().
  123.    * @return <tt>true</tt> if unknown options are ignored.
  124.    * 
  125.    * Since: 2.6.
  126.    */
  127.   bool get_ignore_unknown_options() const;
  128.  
  129.  
  130.   /** Parses the command line arguments, recognizing options
  131.    * which have been added to @a context . A side-effect of 
  132.    * calling this function is that g_set_prgname() will be
  133.    * called.
  134.    * 
  135.    * If the parsing is successful, any parsed arguments are
  136.    * removed from the array and @a argc  and @a argv  are updated 
  137.    * accordingly. A '--' option is stripped from @a argv 
  138.    * unless there are unparsed options before and after it, 
  139.    * or some of the options after it start with '-'. In case 
  140.    * of an error, @a argc  and @a argv  are left unmodified. 
  141.    * 
  142.    * If automatic <option>--help</option> support is enabled
  143.    * (see g_option_context_set_help_enabled()), and the 
  144.    *  @a argv  array contains one of the recognized help options,
  145.    * this function will produce help output to stdout and
  146.    * call <tt>exit (0)</tt>.
  147.    * @param argc A pointer to the number of command line arguments.
  148.    * @param argv A pointer to the array of command line arguments.
  149.    * @param error A return location for errors.
  150.    * @return <tt>true</tt> if the parsing was successful, 
  151.    * <tt>false</tt> if an error occurred
  152.    * 
  153.    * Since: 2.6.
  154.    */
  155.   bool parse(int& argc, char**& argv);
  156.  
  157.   //g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group()
  158.   //- a group without callbacks seems to do some simple default parsing.
  159.   
  160.   
  161.   /** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group. 
  162.    * Note that the group will not be copied, so it should exist for as long as the context exists.
  163.    *
  164.    * @param group The group to add.
  165.    */
  166.   void add_group(OptionGroup& group);
  167.   
  168.   
  169.   /** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only 
  170.    * difference is that the options in the main group are treated differently when generating --help output.
  171.    * Note that the group will not be copied, so it should exist for as long as the context exists.
  172.    *
  173.    * @param group The group to add.
  174.    */
  175.   void set_main_group(OptionGroup& group);
  176.   
  177.   
  178.   //We don't need this (hopefully), and the memory management would be really awkward.
  179.   //OptionGroup& get_main_group();
  180.   //const OptionGroup& get_main_group() const;
  181.   
  182.  
  183.   GOptionContext*       gobj()       { return gobject_; }
  184.   const GOptionContext* gobj() const { return gobject_; }
  185.  
  186. protected:
  187.  
  188.   GOptionContext* gobject_;
  189.   bool has_ownership_;
  190.  
  191.  
  192. };
  193.  
  194.  
  195. } // namespace Glib
  196.  
  197.  
  198. #endif /* _GLIBMM_OPTIONCONTEXT_H */
  199.  
  200.